(*
     camlflickr - examples/uploader
     Copyright (C) 2008  Zachary R. Anderson (zanderso@gmail.com)
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License along
     with this program; if not, write to the Free Software Foundation, Inc.,
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)

(*

Authenticate, then upload ~/testpicture.jpg.

*)

open Camlflickr
open Camlflickr.Xmlutil

module X = Xml

let webbrowser = "firefox"

let api_key = "58a83a4e789fd95dd9d31ac11d825e38"
let api_secret = "e2f973126ee0dc09"

let open_browser (url : string) : unit =
    ignore(Sys.command(webbrowser^" \""^url^"\""))

let upload_test () : unit =
    let flickr = new flickrClass api_key api_secret in
    let (frob,token) = flickr#getTokenPartOne open_browser "write" in
    if token = "" then ignore(read_line ());
    let _ = flickr#getTokenPartTwo token frob in
    let file = (Unix.getenv "HOME")^"/testpicture.jpg" in
    let res = flickr#uploadCall file [("title","Test");("is_public","0")] in
    Printf.printf "Res =\n%s\n" (X.to_string_fmt (X.parse_string res))

let _ = upload_test();;
